package net.risesoft.risereport.obj.authorization.dao;

import java.util.Collection;
import java.util.List;

import net.risesoft.risereport.obj.authorization.domain.User;

import org.appfuse.dao.jdbc.BaseDaoJdbc;
import org.springframework.dao.DataAccessException;

import cn.newtest.common.dbutils.handlers.MultiColumnRowMapper;

/**
 * <p>
 * Title: RiseReport
 * </p>
 * <p>
 * Description: RiseReport
 * </p>
 * <p>
 * Copyright: Copyright (c) 2004 2006
 * </p>
 * <p>
 * Company: SZRiseSoft
 * </p>
 * 
 * @author WangChui(baiyibing@gmail.com)
 * @version 1.0 TODO
 * 
 */
public class AuthorizationDAOImpl extends BaseDaoJdbc implements
		AuthorizationDAO {

	public Collection findAllUser() throws DataAccessException {
		// TODO Auto-generated method stub
		String sql = "select * from rpt_user a   ";

		MultiColumnRowMapper r = new MultiColumnRowMapper(User.class,
				this.getRowProcessor());
		return this.getJdbcTemplate().query(sql, r);
	}

	public User findUserByNameAndPwd(String name, String pwd)
			throws DataAccessException {
		// TODO Auto-generated method stub
		String sql = "select * from rpt_user a where a.username=? and a.password=?";

		// RowResult2BeanReader r = new RowResult2BeanReader(ReportRegion.class,
		// rowProcessor);
		MultiColumnRowMapper r = new MultiColumnRowMapper(User.class,
				this.getRowProcessor());
		List list = this.getJdbcTemplate().query(sql,
				new Object[] { name, pwd }, r);
		if ((list != null) && (list.size() > 0)) {
			return (User) list.get(0);
		}
		return null;
	}

}